package main.java.strategy;

import main.java.strategy.impl.MyATypeImpl;
import main.java.strategy.impl.MyBTypeImpl;
import main.java.strategy.impl.MyDefaultTypeImpl;

import java.util.HashMap;

/**
 * @author xin麒
 * @date 2023/2/2 12:14
 */
public class MyStrategySolution {
    HashMap<Character, MyCharacterType> map = new HashMap<>();

    public MyStrategySolution() {//初始化了，写的比较low,如果使用反射来实现会高级些。
        MyATypeImpl myAType = new MyATypeImpl();
        MyBTypeImpl myBType = new MyBTypeImpl();
        MyDefaultTypeImpl myDefaultType = new MyDefaultTypeImpl();
        map.put(myAType.getCharacterTypeByType(), myAType);
        map.put(myBType.getCharacterTypeByType(), myBType);
        map.put(myDefaultType.getCharacterTypeByType(), myDefaultType);
    }

    public void resolveCharacterType(char charType, Object obj) {
        MyCharacterType myCharacterType = map.get(charType);
        if (myCharacterType != null) {
            myCharacterType.showCharacterType(obj);
        }
    }
}
